home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / programming / aros / utility / utility_init.c < prev    next >
C/C++ Source or Header  |  1996-09-12  |  4KB  |  160 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: utility_init.c,v 1.5 1996/09/11 16:54:31 digulla Exp $
  4.     $Log: utility_init.c,v $
  5.     Revision 1.5  1996/09/11 16:54:31  digulla
  6.     Always use __AROS_SLIB_ENTRY() to access shared external symbols, because
  7.         some systems name an external symbol "x" as "_x" and others as "x".
  8.         (The problem arises with assembler symbols which might differ)
  9.  
  10.     Revision 1.4  1996/09/11 14:03:56  digulla
  11.     Quick hack to make it work again.
  12.  
  13.     Revision 1.3  1996/08/13 14:11:54  digulla
  14.     Replaced __AROS_LA by __AROS_LHA
  15.  
  16.     Revision 1.2  1996/08/01 17:41:42  digulla
  17.     Added standard header for all files
  18.  
  19.     Desc:
  20.     Lang:
  21. */
  22. #include <exec/resident.h>
  23. #include <clib/exec_protos.h>
  24. #include <aros/libcall.h>
  25. #include <dos/dos.h>
  26. #include "utility_intern.h"
  27. /* #include <utility/utility.h> */
  28.  
  29. static const char name[];
  30. static const char version[];
  31. static const APTR inittabl[4];
  32. static void *const Utility_functable[];
  33. struct UtilityBase *__AROS_SLIB_ENTRY(init,Utility) ();
  34. extern const char Utility_end;
  35.  
  36. int Utility_entry(void)
  37. {
  38.     /* If the library was executed by accident return error code. */
  39.     return -1;
  40. }
  41.  
  42. const struct Resident Utility_resident=
  43. {
  44.     RTC_MATCHWORD,
  45.     (struct Resident *)&Utility_resident,
  46.     (APTR)&Utility_end,
  47.     RTF_AUTOINIT,
  48.     39,
  49.     NT_LIBRARY,
  50.     0,
  51.     (char *)name,
  52.     (char *)&version[6],
  53.     (ULONG *)inittabl
  54. };
  55.  
  56. static const char name[]=UTILITYNAME;
  57.  
  58. static const char version[]="$VER: utility 39.0 (5.6.96)\n\015";
  59.  
  60. static const APTR inittabl[4]=
  61. {
  62.     (APTR)sizeof(struct UtilityBase),
  63.     (APTR)Utility_functable,
  64.     NULL,
  65.     &__AROS_SLIB_ENTRY(init,Utility)
  66. };
  67.  
  68. #ifdef SysBase
  69. #undef SysBase
  70. #endif
  71. #define SysBase UtilityBase->ub_SysBase
  72.  
  73. __AROS_LH2(struct UtilityBase *, init,
  74.  __AROS_LHA(struct UtilityBase *, UtilityBase, D0),
  75.  __AROS_LHA(BPTR,               segList,   A0),
  76.        struct ExecBase *, sysBase, 0, Utility)
  77. {
  78.     __AROS_FUNC_INIT
  79.  
  80.     /* Store arguments */
  81.     UtilityBase->ub_SysBase=sysBase;
  82.     UtilityBase->ub_SegList=segList;
  83.  
  84.     /* You would return NULL if the init failed */
  85.     return UtilityBase;
  86.     __AROS_FUNC_EXIT
  87. }
  88.  
  89. __AROS_LH1(struct UtilityBase *, open,
  90.  __AROS_LHA(ULONG, version, D0),
  91.        struct UtilityBase *, UtilityBase, 1, Utility)
  92. {
  93.     __AROS_FUNC_INIT
  94.  
  95.     /* Keep compiler happy */
  96.     version=0;
  97.  
  98.     /* I have one more opener. */
  99.     UtilityBase->ub_LibNode.lib_OpenCnt++;
  100.     UtilityBase->ub_LibNode.lib_Flags&=~LIBF_DELEXP;
  101.  
  102.     /* You would return NULL if the open failed. */
  103.     return UtilityBase;
  104.     __AROS_FUNC_EXIT
  105. }
  106.  
  107. __AROS_LH0(BPTR, close,
  108.        struct UtilityBase *, UtilityBase, 2, Utility)
  109. {
  110.     __AROS_FUNC_INIT
  111.  
  112.     /* I have one fewer opener. */
  113.     if(!--UtilityBase->ub_LibNode.lib_OpenCnt)
  114.     {
  115.     /* Delayed expunge pending? */
  116.     if(UtilityBase->ub_LibNode.lib_Flags&LIBF_DELEXP)
  117.         /* Then expunge the library */
  118.         return expunge();
  119.     }
  120.     return 0;
  121.     __AROS_FUNC_EXIT
  122. }
  123.  
  124. __AROS_LH0(BPTR, expunge,
  125.        struct UtilityBase *, UtilityBase, 3, Utility)
  126. {
  127.     __AROS_FUNC_INIT
  128.  
  129.     BPTR ret;
  130.  
  131.     /* Test for openers. */
  132.     if(UtilityBase->ub_LibNode.lib_OpenCnt)
  133.     {
  134.     /* Set the delayed expunge flag and return. */
  135.     UtilityBase->ub_LibNode.lib_Flags|=LIBF_DELEXP;
  136.     return 0;
  137.     }
  138.  
  139.     /* Get rid of the library. Remove it from the list. */
  140.     Remove(&UtilityBase->ub_LibNode.lib_Node);
  141.  
  142.     /* Get returncode here - FreeMem() will destroy the field. */
  143.     ret=UtilityBase->ub_SegList;
  144.  
  145.     /* Free the memory. */
  146.     FreeMem((char *)UtilityBase-UtilityBase->ub_LibNode.lib_NegSize,
  147.         UtilityBase->ub_LibNode.lib_NegSize+UtilityBase->ub_LibNode.lib_PosSize);
  148.  
  149.     return ret;
  150.     __AROS_FUNC_EXIT
  151. }
  152.  
  153. __AROS_LH0I(int, null,
  154.         struct UtilityBase *, UtilityBase, 4, Utility)
  155. {
  156.     __AROS_FUNC_INIT
  157.     return 0;
  158.     __AROS_FUNC_EXIT
  159. }
  160.